home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / bin / fontconfig-voodoo < prev    next >
Text File  |  2009-10-23  |  3KB  |  102 lines

  1. #!/usr/bin/python
  2.  
  3. import os
  4. import sys
  5. from optparse import OptionParser
  6.  
  7. from LanguageSelector import FontConfig
  8. from gettext import gettext as _
  9.  
  10.  
  11. def main():
  12.     
  13.     def abort(msg=None):
  14.         " helper for a clean abort "
  15.         if not options.silent:
  16.             if msg:
  17.                 print msg
  18.             print _("Aborting")
  19.         sys.exit(1)
  20.  
  21.     usage = "usage: %prog [options]"
  22.     # init the option parser
  23.     parser = OptionParser(usage)
  24.     parser.add_option("-f", "--force", dest="force",
  25.                       action="store_true",
  26.                       help=_("Force even when a configuration exists"))
  27.     parser.add_option("-s", "--set", dest="lang",
  28.                       help=_("Set fontconfig voodoo for the selected "
  29.                              "language"))
  30.     parser.add_option("-a", "--auto", dest="auto",
  31.                       action="store_true",
  32.                       help=_("Guess a configuration based on the "
  33.                              "LANGUAGE environment. Sets the config to "
  34.                              "'none' if nothing suitable was found"))
  35.     parser.add_option("-l", "--list", dest="list",
  36.                       action="store_true",
  37.                       help=_("List the available fontconfig-voodoo configs"))
  38.     parser.add_option("-c", "--current", dest="show_current",
  39.                       action="store_true",
  40.                       help=_("Show the current fontconfig-voodoo config"))
  41.     parser.add_option("-r", "--remove-current", dest="remove_current",
  42.                       action="store_true",
  43.                       help=_("Remove the current fontconfig-voodoo config"))
  44.     parser.add_option("-q", "--quiet",
  45.                       action="store_true", dest="silent", default=False)
  46.  
  47.     # check if we have arguments at all
  48.     if len(sys.argv[1:]) == 0:
  49.         parser.print_help()
  50.         sys.exit(0)
  51.  
  52.     # parse them
  53.     (options, args) = parser.parse_args()
  54.  
  55.     # do the work
  56.     fc = FontConfig.FontConfigHack()
  57.  
  58.     if options.show_current:
  59.         try:
  60.             if options.silent:
  61.                 print fc.getCurrentConfig()
  62.             else:
  63.                 print "Current config: %s" % fc.getCurrentConfig()
  64.         except FontConfig.ExceptionUnconfigured:
  65.             print _("Unconfigured")
  66.         sys.exit(0)
  67.  
  68.     if options.list:
  69.         print "\n".join(fc.getAvailableConfigs())
  70.         sys.exit(0)
  71.         
  72.     if not options.force:
  73.         try:
  74.             fc.getCurrentConfig()
  75.             # if this does not raise a "Unconfigured" exception, we
  76.             # abort here
  77.             abort(_("A configuration exists already. Use '--force' to "
  78.                     "overwrite it. "))
  79.         except FontConfig.ExceptionUnconfigured:
  80.             pass
  81.  
  82.     if options.auto:
  83.         try:
  84.             fc.setConfigBasedOnLocale()
  85.         except FontConfig.ExceptionNoConfigForLocale:
  86.             pass
  87.  
  88.     if options.remove_current:
  89.         fc.removeConfig()
  90.         sys.exit(0)
  91.  
  92.     if options.lang:
  93.         try:
  94.             fc.setConfig(options.lang)
  95.         except FontConfig.ExceptionNoConfigForLocale:
  96.             abort(_("No fontconfig-voodoo configuration found for the "
  97.                     "selected locale"))
  98.  
  99.     
  100. if __name__ == "__main__":
  101.     main()
  102.